package com.byq.mm.smartlib.obd.commands.fuel;

import com.byq.mm.smartlib.obd.commands.AbstractObdCommand;
import com.byq.mm.smartlib.obd.enums.FuelTrim;


/** * Get Fuel Trim. * */
public class FuelTrimObdCommand extends AbstractObdCommand {
	private float fuelTrimValue = 0.0f;
	private final FuelTrim bank;

	/**
	 * * Default ctor. * * Will read the bank from parameters and construct the
	 * command accordingly. * Please, see FuelTrim enum for more details.
	 */
	public FuelTrimObdCommand(FuelTrim bank) {
		super(bank.getObdCommand());
		this.bank = bank;
	}

	/** * @param value * @return */
	private float prepareTempValue(int value) {
		Double perc = (value - 128) * (100.0 / 128);
		return Float.parseFloat(perc.toString());
	}

	@Override
	public String getFormattedResult() {
		if (!"NODATA".equals(getResult())) {
			fuelTrimValue = prepareTempValue(buffer.get(2));
		}
		return String.format("%.2f%s", fuelTrimValue, "%");
	}

	/** * @return the readed Fuel Trim percentage value. */
	public final float getValue() {
		return fuelTrimValue;
	}

	/** * @return the name of the bank in string representation. */
	public final String getBank() {
		return bank.getBank();
	}

	@Override
	public String getName() {
		return bank.getBank();
	}

	@Override
	public String getRequestKey() {
		// TODO Auto-generated method stub
		return null;
	}
}
